﻿<div class="layui-row">
    <div class="layui-col-md3">
        <div class="layui-body-nav">笔记 / 笔记列表
            <a data-id="2" class="layui-btn layui-btn-normal layui-btn-xs action-add_projectnote">添加笔记</a>
        </div>
        <table class="layui-hide" id="table-projectnote" lay-filter="table-projectnote"></table>
    </div>
    <div class="layui-col-md9" id="layui-body-projectnote">
    </div>
</div>
<!-- layui规范化用法 -->
<script type="text/javascript">
    var table = null;
    /*菜单*/
    workUtils.onclick(".layui-icon-menu",function (c) {
        $(".widget-menu").hide();
        $(c).next().toggle();
    })
    /*历史版本*/
    workUtils.onclick(".action-projecthistory",function (c) {
        var id = $(c).data("id");
        workUtils.put("noteId", id);
        workUtils.open({url: "../web/project/history.html", title: "历史版本", width: '1100px', height: "600px"})
    });
    /*删除笔记*/
    workUtils.onclick(".action-projectdelete", function (c) {
        var id = $(c).attr("data-id");
        workUtils.delete('../note/delete/' + id, function () {
            loadProjectNote(projectId);
        })
    });
    /*添加笔记*/
    workUtils.onclick(".action-add_projectnote", function () {
        loadProjectNoteFirst();
    });
    /*加载某个笔记*/
    function loadProjectNoteFirst(noteId) {
        workUtils.put("noteId", noteId);
        workUtils.html({
            url: "../web/project/addnote.html",
            id: 'layui-body-projectnote'
        }, function () {
            alert(0);
        });
    }
    /*刷新笔记*/
    function loadDefaultData() {
        table.reload("table-projectnote", {
            where: {
                projectId: workUtils.get("projectId")
            }
        });
    }
    layui.use(['layer', 'table'], function () {
        table = layui.table;
        table.render({
            elem: '#table-projectnote'
            , url: '../project/listnote'
            , height: 'full-145'
            , cols: [[
                {field: 'name', title: '标题', width: 'auto', align: 'left', event: 'edit'}
            ]]
            , where: {
                projectId: workUtils.get("projectId")
            }
            , page: {
                layout: ['prev', 'next'],
                prev: '上一页',
                next: '下一页',
            }
            , cell: function (field, item) {
                if (field == "created") {
                    return workUtils.toDate(item.created);
                } else if (field == "name") {
                    var html = '<div class="title">' + item.name + '</div>';
                    html += '<div class="layui-row">';
                    html += '<div class="layui-col-md8">';
                    html += workUtils.toDate(item.created) +' V'+item.version +" By "+item.lastUserName;
                    html += '</div>';
                    html += '<div class="layui-col-md4  menu-bars">';
                    html += '<i class="layui-icon layui-icon-menu" style="font-size: 30px; color: #1E9FFF;">&#xe65f;</i>  ';
                    html += '<dl class="widget-menu">';
                    html += '<dd  data-id="' + item.id + '" class="action-projecthistory">历史</dd> ';
                    html += '<dd  data-id="' + item.id + '" class="action-projectdelete">删除</dd> ';
                    html += '</dl></div>';
                    html += '</div>';
                    return html;
                }
                return item[field];
            }
        });
        //监听工具条
        table.on('tool(table-projectnote)', function (obj) {
            var data = obj.data;
            loadProjectNoteFirst(data.id);
        });
    });


</script>